package com.zany.util.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

import com.zany.system.vo.ParameterMultiVO;
import com.zany.util.ZanyErrorMsg;
import com.zany.util.ZanyException;
import com.zany.util.ajax.AjaxTools;
import com.zany.util.json.JSONArray;
import com.zany.util.json.JSONException;
import com.zany.util.json.JSONObject;
import com.zany.util.service.MultiParamUtilService;

public class MultiParamAction extends AbstractActionSupport{

	private static final long serialVersionUID = -7092718028506031463L;
	private static Log logger = LogFactory.getLog(MultiParamAction.class);
	private MultiParamUtilService multiParamUtilService;
	private ParameterMultiVO parameterMultiVO = new ParameterMultiVO();
	private List<ParameterMultiVO> parameterList = new ArrayList<ParameterMultiVO>();
	
	public void getMultiParam() throws ZanyException {
		if(logger.isInfoEnabled()){logger.info("MultiParamAction.getMultiParam()");}
		response = ServletActionContext.getResponse();
		parameterMultiVO.setParamCode(request.getParameter("paramCode"));
		parameterList = multiParamUtilService.getMultiParamList(parameterMultiVO);
		JSONArray listJson = new JSONArray();
		try{
			for(ParameterMultiVO vo:parameterList){
				JSONObject json = new JSONObject();
				json.put("key",vo.getOptionValue());
				json.put("value",vo.getOptionText().trim());
				listJson.put(json);
			}
		}catch(JSONException e){
			throw new ZanyException(ZanyErrorMsg.ERR_DEFAULT,e.getMessage(),e);
		}
		String json = "{param:"+listJson.toString()+"}";
		AjaxTools.exAjax(json,response);
	}
	
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub	
	}

	public MultiParamUtilService getMultiParamUtilService() {
		return multiParamUtilService;
	}

	public void setMultiParamUtilService(MultiParamUtilService multiParamUtilService) {
		this.multiParamUtilService = multiParamUtilService;
	}

}
